using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using ilgolosone.Shared.Domain;

namespace ilgolosone.Shared.Data
{
    /// <summary>
    /// Classe che definisce una implementazione non specializzata di <see cref="IRepository{TEntity}"/>
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    public abstract class RepositoryBase<TEntity> : IRepository<TEntity> where TEntity : IAggregateRoot
    {
        protected abstract IQueryable<TEntity> RepositoryQuery { get; }

        public IEnumerator<TEntity> GetEnumerator()
        {
            return RepositoryQuery.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return RepositoryQuery.GetEnumerator();
        }

        public Expression Expression
        {
            get { return RepositoryQuery.Expression; }
        }

        public Type ElementType
        {
            get { return RepositoryQuery.ElementType; }
        }

        public IQueryProvider Provider
        {
            get { return RepositoryQuery.Provider; }
        }

        public abstract TEntity Get(Guid id);
        public abstract void Save(TEntity item);
        public abstract void Delete(TEntity item);
        public abstract void DeleteAll();
        public abstract void Dispose();
    }
}